package com.dq.domain.record;

import com.dq.vo.baseVo.VO;
import com.dq.domain.org.Org;
import com.dq.domain.sys.user.user.base.SysUser;
import com.dq.utils.TimeUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.ManyToOne;

/**
 * @author liuhui
 * @date 2019/11/20 0020 11:55:43
 */
@Data
@Entity
@ApiModel("微信用户变更记录")
public class WxUserChangeRecord extends UserChangeRecord implements VO.ToVO {

    @ManyToOne
    @ApiModelProperty("原来的技师")
    protected SysUser originalStaffUser;

    @ManyToOne
    @ApiModelProperty("现在的技师")
    protected SysUser nowStaffUser;

    @ManyToOne
    @ApiModelProperty("原来的门店")
    protected Org originalOrg;

    @ManyToOne
    @ApiModelProperty("现在的门店")
    protected Org nowOrg;

    @ApiModelProperty("变更类型")
    @Enumerated(EnumType.ORDINAL)
    protected WxUserChangeType wxUserChangeType;



    public enum WxUserChangeType{
        org("变更门店"),
        technician("变更技师");

        public String name;

        WxUserChangeType (String name){
            this.name = name;
        }
    }


    @Data
    @ApiModel(value = "微信用户变更记录视图")
    public static class Vo implements VO {

    }

    @Override
    public VO toVO(boolean isRecursion) {
        Vo vo = new Vo();

        return vo;
    }

    @Data
    @ApiModel(value = "顾客变更记录")
    public static class WxUserChangeRecordVo{
        @ApiModelProperty("id")
        protected Long id;
        @ApiModelProperty("原门店")
        protected String orgName;
        @ApiModelProperty("现门店")
        protected String nowOrgName;
        @ApiModelProperty("员工工号")
        protected String cardNo;
        @ApiModelProperty("员工姓名")
        protected String userRealcName;
        @ApiModelProperty("原技师")
        protected String staffUserName;
        @ApiModelProperty("现技师")
        protected String nowStaffUserName;
        @ApiModelProperty("变更类别")
        protected String type;
        @ApiModelProperty("创建时间")
        protected String createTime;
        @ApiModelProperty("创建人")
        protected String createUserName;
    }

    public WxUserChangeRecordVo toStaffUserChangeRecordVo(){
        WxUserChangeRecordVo vo = new WxUserChangeRecordVo();
        vo.id = fmt(this.id);
        vo.nowOrgName = this.nowOrg != null ? fmt(this.nowOrg.getSimpleName()):"";
        vo.orgName = fmt(this.originalOrg.getSimpleName());
        vo.cardNo = fmt(this.sysUser.getCardNo());
        vo.staffUserName = fmt(this.originalStaffUser.getUserRealcName());
        vo.nowStaffUserName = this.nowStaffUser.getUserRealcName() != null ? fmt(this.nowStaffUser.getUserRealcName()):"";
        vo.userRealcName = this.sysUser != null ? fmt(this.sysUser.getUserRealcName()):"";
        vo.type = fmt(this.wxUserChangeType.name);
        vo.createTime = fmt(this.createTime, TimeUtil.YYYY_MM_DD_HH_MM_SS);
        vo.createUserName = fmt(this.createUser.getUserRealcName());
        return vo;
    }
}
